package com.sws.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sws.domain.News;
import com.sws.mapping.BannerMapper;
import com.sws.mapping.ClazzMapper;
import com.sws.mapping.FormMapper;
import com.sws.mapping.LevelMapper;
import com.sws.mapping.NewsMapper;
import com.sws.mapping.StateMapper;
import com.sws.mapping.TypeMapper;
import com.sws.model.bean.C2SPageBean;
import com.sws.model.bean.S2CNewsBean;
import com.sws.service.HomeService;

@Service
public class HomeServiceImpl implements HomeService {
	
	@Autowired
	private BannerMapper bannerMapper;
	@Autowired
	private NewsMapper newsMapper;
	@Autowired
	private FormMapper formMapper;
	@Autowired
	private LevelMapper levelMapper;
	@Autowired
	private TypeMapper typeMappr;
	@Autowired
	private StateMapper stateMapper;
	@Autowired
	private ClazzMapper calzzMapper;
	private static List<String> authors = new ArrayList<>();
	private static List<String> ranks = new ArrayList<>();
	static {
		authors.add("第一作者");
		authors.add("第二作者");
		authors.add("第三作者");
		authors.add("其他");
		ranks.add("A");
		ranks.add("B");
		ranks.add("C");
		ranks.add("Other");
	}

	@Override
	public List getPushBanner() {
		// TODO Auto-generated method stub
		return bannerMapper.getPushBanner();
	}

	@Override
	public List getPushNews(C2SPageBean bean) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		map.put("user", bean.getUser());
		map.put("skips", (bean.getPages()-1)*bean.getLimits());
		map.put("limits", bean.getLimits());
		return newsMapper.getPushNews(map);
	}

	@Override
	public S2CNewsBean getNews(Integer id) {
		// TODO Auto-generated method stub
		return newsMapper.getNews(id);
	}

	@Override
	public Map getBaseData() {
		// TODO Auto-generated method stub
		Map<String, List> map = new HashMap<>();
		map.put("form", formMapper.selectAll());
		map.put("level", levelMapper.selectAll());
		map.put("clazz", calzzMapper.selectAll());
		map.put("type", typeMappr.selectAll());
		map.put("state", stateMapper.selectAll());
		map.put("author", authors);
		map.put("rank", ranks);
		return map;
	}

}
